/**
 * 
 */
package com.cipe.cmrs.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Keyword;
import com.cipe.cmrs.model.User;
import com.cipe.cmrs.util.DateUtil;

/**
 * @author Incepio
 */
@Service
@Transactional
public class KeywordService extends BaseService<Keyword> {

	@Autowired
	private UserService	userService;

	public Keyword saveKeyword(Keyword keyword, Integer userId) {
		if (keyword != null) {
			User user = userService.findById(userId);
			Keyword dbKeyword = findById(keyword.getId());
			if (dbKeyword == null) {
				dbKeyword = new Keyword();
				dbKeyword.setCreatedBy(user);
				dbKeyword.setCreationDate(DateUtil.getCurrentDate());
			}
			dbKeyword.setDisplayName(keyword.getDisplayName());
			dbKeyword.setDescription(keyword.getDescription());
			dbKeyword.setUpdatedBy(user);
			dbKeyword.setUpdationDate(DateUtil.getCurrentDate());
			return merge(dbKeyword);
		}
		return null;
	}
}
